package captcha

import (
	"errors"
	"github.com/mojocn/base64Captcha"
	"github.com/sirupsen/logrus"
	"study/server/global"
)

var Store = base64Captcha.DefaultMemStore

// 生成验证码图片
func GenerateCaptcha() (string, string, string, error) {
	var driver = base64Captcha.DriverString{
		Width:           200,
		Height:          60,
		NoiseCount:      2,
		ShowLineOptions: 4,
		Length:          global.Config.Captcha.Length,
		Source:          "0123456789",
	}
	cp := base64Captcha.NewCaptcha(&driver, Store)
	id, b64s, answer, err := cp.Generate()
	if err != nil {
		logrus.Errorf("图片验证码生成失败 %s", err)
		return "", "", "", errors.New("图片验证码生成失败")

	}
	return id, b64s, answer, nil
}
